-module(clique).
-export([cliques/1]).

cliques(G)->
    cliques(graph:v(G),
	    [],
	    [],
	    G).

cliques(N,D,S,G)->
    case set:empty(set:join(N,D)) of
	true ->
	    io_graph:print_cliq(S,G);
	false -> case set:empty(N) of
		    false ->
			F = set:get_el(N),
			NewN = set:diff(N, [F]),
			cliques( set:cross(NewN, graph:adj(F, G)),
				 set:cross(D,
					   graph:adj(F, G)),
				 set:add(F,S),
				 G),
			loop(NewN,
			     set:add(F,D),
			     S,
			     set:cross(NewN,
				       set:diff(graph:v(G),graph:adj(F,G))),
			     G);
		    true ->ok
		end
    end.

loop(_,_,_,[],_)->
    ok;
loop(N,D,S, [F | Tail] ,G)->
    NewN = set:diff(N, [F]),
    cliques(set:cross(NewN, graph:adj(F,G)),
	    set:cross(D, graph:adj(F,G)),
	    set:add(F,S),
	    G),
    loop(NewN,
	 set:add(F,D),
	 S,
	 Tail,
	 G).
	    
    
    
